package com.briup.smartcity.web.controller;

import com.briup.smartcity.aop.Logging;
import com.briup.smartcity.bean.Comment;
import com.briup.smartcity.service.ICommentService;
import com.briup.smartcity.utils.Result;
import com.briup.smartcity.utils.ResultUtil;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "评论管理模块")
@RestController
@RequestMapping("/auth/comment")
public class CommentController {
    @Autowired
    private ICommentService service;
    @Logging()
    @ApiOperation(value = "批量删除评论信息",notes = "参数格式：ids=1&ids=2")
    @DeleteMapping("/batchDelete")
    public Result batchDelete(int[] ids){
        service.batchDelete(ids);
        return ResultUtil.success();
    }

    @ApiOperation("审核评论状态")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "评论编号"),
            @ApiImplicitParam(name = "status",value = "状态")
    })
    @PutMapping("/check")
    public Result checkComment(int id,int status){
        service.checkComment(id,status);
        return ResultUtil.success();
    }

    @ApiOperation("通过id删除评论信息")
    @ApiImplicitParam(name = "id",value = "评论编号")
    @DeleteMapping("/deleteById")
    public Result deleteById(Integer id){
        service.deleteById(id);
        return ResultUtil.success();
    }

    @ApiOperation("分页查询评论信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "keywords",value = "评论内容关键字"),
            @ApiImplicitParam(name = "pageNum",value = "当前页数"),
            @ApiImplicitParam(name = "pageSize",value = "每页数量")
    })
    @GetMapping("/pageQuery")
    public Result PageQuery(String keywords,Integer pageNum,Integer pageSize){
        PageInfo<Comment> pageInfo = service.pageQuery(keywords, pageNum, pageSize);
        return ResultUtil.success(pageInfo);
    }
}
